<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ page language="java" import="com.bean.MessageBean"%>
<%@ page language="java" import="com.bean.UserBean"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<% 
	MessageBean message = (MessageBean)request.getAttribute("key");
	@SuppressWarnings("unchecked")
	ArrayList<UserBean> list = (ArrayList<UserBean>)request.getAttribute("users");
	
%>
<head>
    <base href="<%=basePath%>">
    
    <title>user</title>
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<link rel="stylesheet" type="text/css" href="CSS/style.css">
	<script type="text/javascript" src="JS/table.js"></script>

	<script type="text/javascript">
		function check(form)
		{
			if(form.limits.value == "")
			{
			alert("please select the query Builder");return false;}
			
			if(form.userkey.value == "")
			{alert("please enter the query content");return false;}
			if(form.limits.value=="userid" &&  form.userkey.value.length > 8)
			{
				alert("please confirm content, 8 bits");return false;
			}
			if(form.limits.value=="userid" && !/^\d+$/.test(form.userkey.value))
			{
				alert("please confirm content, number is expected");return false;
			}
			else if(form.limits.value!="userid" &&!/^[A-Za-z]+$/.test(form.userkey.value))
			{alert("please confirm content,the character is expected");return false;}
			
			form.submit();
		}
	</script>

</head>
<body bgcolor="#FFFFFF">

<table width="778"  border="0" cellspacing="0" cellpadding="0" align="center" bordercolor="#D1D1D1">
  <tr>
    <td valign="top" bgcolor="#FFFFFF"><table width="99%" height="510"  border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF" class="tableBorder_gray">
  <tr>
    <td height="510" valign="top" style="padding:5px;"><table width="98%" height="487"  border="0" cellpadding="0" cellspacing="0">
      <tr>
        <td height="22" valign="top" class="current_addr">&nbsp;Current address：User &gt;&gt; Query</td>
      </tr>
      <tr>
        <td align="center" valign="top">
 <%
 String key = "userid";
 String value = "";
 if(message!=null)
 {
  	 key = message.getKey();
  	 value = message.getValue();
 }   
%>
       
<form action="UserQueryServlet" method="post" name="form1" style="border: 0">  
 <table width="99%" height="48"  border="0" cellpadding="0" cellspacing="0" bgcolor="#E3F4F7">
  <tr>
    <td align="center">&nbsp;<img src="images/searchp.png" width="48" height="48"></td>
    <td>Query Criteria:
      <select name="limits" id="f">
        <option value="userid"<%if(key.equals("userid")){%> selected <%}%>>ID</option>
        <option value ="firstname"<%if(key.equals("firstname")){%> selected <%}%> >Firstname</option>
        <option value ="lastname"<%if(key.equals("lastname")){%> selected <%}%>>Surname</option>
      </select>

      <input name="userkey" type="text" id="key" size="50" value="<%=value%>">

      <input name="search" type="button" class="btn" value="search" onClick="check(form1)"></td>
  </tr>
</table>
</form>
          
         <%if((list==null) || (list.isEmpty()))
    	    {%>
          <table width="100%" height="30"  border="0" cellpadding="0" cellspacing="0">
            <tr>
              <td height="36" align="center" class="record"><font color="red">No records</font></td>
            </tr>
          </table>
         
          
          <table width="100%"  border="0" cellspacing="0" cellpadding="0">
  			<tr>
   			 <td>
      		<a href="/lab/lab_admin/user_add.jsp" class="add">&nbsp;Add user</a></td>
			 </tr>
			</table>
          <%}else{%>
          
    	<table width="100%" height="30"  border="0" cellpadding="0" cellspacing="0">
            <tr>
              <td height="36" align="center" class="record"><font color="green">SUCCESS</font></td>
            </tr>
          </table>
         
          
          <table width="100%"  border="0" cellspacing="0" cellpadding="0">
  			<tr>
   			 <td>
      		<a href="UserAddServlet?option=usertypelist" class="add">&nbsp;Add user</a></td>
			 </tr>
			</table>      
 	<%} %>
          
<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td height="30" background="images/tab_05.gif"><table width="100%" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td width="12" height="30"><img src="images/tab_03.gif" width="12" height="30" /></td>
        <td><table width="100%" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td width="46%" valign="middle">          
            <table width="100%" border="0" cellspacing="0" cellpadding="0">
              <tr>
                <td width="5%"><div align="center"><img src="images/tb.gif" width="16" height="16" /></div></td>
                <td width="95%" class="STYLE1"><span class="STYLE3">user records</span></td>
              </tr>
            </table></td>
           
          </tr>
        </table></td>
        <td width="16"><img src="images/tab_07.gif" width="16" height="30" /></td>
      </tr>
    </table></td>
  </tr>
  <tr>
    <td>
    <table width="100%" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td width="8" background="images/tab_12.gif">&nbsp;</td>
        <td>
 
      
       <div style="width:100%;height:300;overflow-x:hidden;overflow-y:auto; border: 0">
        <table width="100%" border="0" style="table-layout: fixed;" cellpadding="0" cellspacing="1" bgcolor="b5d6e6" onmouseover="changeto(event);" onmouseout="changeback(event);" onclick="clickto(event);">
          <thead>
          <tr>
            <td width="5%" height="22" background="images/bg.gif" bgcolor="#FFFFFF"><div align="center"><span class="STYLE1">Num</span></div></td>
            <td width="10%" height="22" background="images/bg.gif" bgcolor="#FFFFFF"><div align="center"><span class="STYLE1">ID</span></div></td>
            <td width="10%" height="22" background="images/bg.gif" bgcolor="#FFFFFF"><div align="center"><span class="STYLE1">Firstname</span></div></td>
            <td width="10%" height="22" background="images/bg.gif" bgcolor="#FFFFFF"><div align="center"><span class="STYLE1">Surname</span></div></td>
          	<td width="20%" height="22" background="images/bg.gif" bgcolor="#FFFFFF" class="STYLE1"><div align="center">Email</div></td>
          	<td width="33%" height="22" background="images/bg.gif" bgcolor="#FFFFFF" class="STYLE1"><div align="center">Option</div></td>
          </tr>
          </thead>
          <tbody>
          
 <%if(list != null && !list.isEmpty()) {%>
   <%
 	Iterator<UserBean> iter = list.iterator();
 	String userID = "";
 	String userFirstName = "";
 	String userLastName = "";
 	String email = "";
 	int num = 0;
 	         
		  
    while(iter.hasNext()){ 
    	UserBean bean = iter.next();
       userID = bean.getUserID();
       userFirstName = bean.getFirstname();
       userLastName = bean.getLastname();
       email = bean.getEmail();
       num++;
    %>
          <tr>
            <td height="20" bgcolor="#FFFFFF"><div align="center" class="STYLE1">
              <div align="center"><%=num %></div>
            </div></td>
            <td height="20" bgcolor="#FFFFFF"><div align="center"><span class="STYLE1"><%=userID %></span></div></td>
            <td height="20" bgcolor="#FFFFFF"><div align="center"><span class="STYLE1"><%=userFirstName %></span></div></td>
			<td height="20" bgcolor="#FFFFFF"><div align="center"><span class="STYLE1"><%=userLastName %></span></div></td>
            <td height="20" bgcolor="#FFFFFF"><div align="center"><span class="STYLE1"><%=email %></span></div></td>
            <td height="20" bgcolor="#FFFFFF"><div align="center"><span class="STYLE4">
            	<img src="images/stateuser.png" width="16" height="16" border="0"/><a href="StateQueryServlet?key=userid&value=<%=userID %>" style="text-decoration: none;">state</a>&nbsp;
            	<img src="images/details.png" width="16" height="16" border="0"/><a href="UserDetailServlet?userdetailid=<%=userID %>" style="text-decoration: none;">detail</a>&nbsp;
            	<img src="images/edt.gif" width="16" height="16" border="0"/><a href="UserModifyServlet?usermodifyid=<%=userID %>&key=<%=key %>&value=<%=value %>&option=edit" style="text-decoration: none;">edit</a>&nbsp;
            	<img src="images/del.gif" width="16" height="16" /><a href="UserDeleteServlet?userdeleteid=<%=userID %>&key=<%=key %>&value=<%=value %>" style="text-decoration: none;">delete</a></span></div></td>
          </tr>
	<%} %>
<%} %>
          </tbody>
        </table>
        </div>
        </td>
        <td width="8" background="images/tab_15.gif">&nbsp;</td>
      </tr>
    </table></td>
  </tr>
  <tr>
    <td height="35" background="images/tab_19.gif"><table width="100%" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td  height="35"><img src="images/tab_18.gif" width="12" height="35" /></td>
       
        <td width="16"><img src="images/tab_20.gif" width="16" height="35" /></td>
      </tr>
    </table></td>
  </tr>
</table>

</td>
      </tr>
    </table>
</td>
  </tr>
</table></td>
  </tr>
</table>
</body>
</html>
